/**
 * 
 */
package view;

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
/**
 * @author Rajib
 *
 */
public class application {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			/*messenger window = new messenger();
			window.open();*/
			test();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void test() throws InterruptedException
	{
		 // Create XMPP connection to gmail.com server
	    XMPPConnection connection = new XMPPConnection("gmail.com");
	    
	    try
	    {
	        // Connect
	        connection.connect();
	        
	        // Login with appropriate credentials
	        connection.login("sarb.rb@gmail.com", "01011100");

	        // Get the user's roster
	        Roster roster = connection.getRoster();
	        
	        // Create the presence object with default availability 
	        org.hara.smack.packet.Presence presence = new org.hara.smack.packet.Presence(org.hara.smack.packet.Presence.Type.UNAVAILABLE);

	        // Set the status message
	        presence.setStatus("Online, Programmatically!");
	        
	        // Set the highest priority
	        presence.setPriority(24);
	        
	        // Set available presence mode
	        presence.setMode(org.hara.smack.packet.Presence.Mode.INVISIBLE);
	        
	        // Send the presence packet through the connection
	        connection.sendPacket(presence);
	        
	        
	     // Print the number of contacts
	        System.out.println("Number of contacts: " + roster.getEntryCount());
	        
	        Message message = new Message();
	        message.setTo("itshabib@gmail.com");
	        message.setBody("Test message. (send using google talk plus)");
	        message.setType(Message.Type.chat);
	        connection.sendPacket(message);
	        
	        // Sleep for 20 seconds
	        Thread.sleep(20000);
	        
	        
	        

	        // Enumerate all contacts in the user's roster
	        for (RosterEntry entry : roster.getEntries())
	        {
	            System.out.println("User: " + entry.getUser());
	        }
	    }
	    catch (XMPPException e)
	    {
	        // Do something better than this!
	        e.printStackTrace();
	    }

	}

}
